package code.example.base.util.concurrent.lock.speed;

import code.example.base.util.concurrent.lock.Counter;

import java.util.concurrent.TimeUnit;

public class SpeedRunnable implements  Runnable{
    Counter counter = null;
    int waitTime =10;
    public SpeedRunnable(Counter counter,int waitTime){
        this.counter = counter;
        this.waitTime = waitTime;
    }

    @Override
    public void run() {
        long startTime = System.nanoTime();
        int count = counter.getCount();
        count ++;
       if(waitTime>0){
            try{
                TimeUnit.MILLISECONDS.sleep(waitTime);
            }catch (Exception e){}
        }

        counter.setCount(count);
        if(count %1000 ==0){
            System.out.println("count:"+count+",one time:"+(System.nanoTime()- startTime));
        }
    }
}
